package com.getword.web.controller;


import com.getword.mongodao.SchoolRepository;
import com.getword.service.SchoolService;
import com.getword.web.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/school")
public class ApiSchoolController {
    @Autowired
    private SchoolRepository schoolRepository;
    @Autowired
    private SchoolService schoolService;

    @GetMapping
    public Result query(Integer countyId){

        return Result.success(schoolRepository.findSchoolsByCountyIdOrderByFirstPy(countyId));
    }
    //根据ID查询学校
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Long id){
        return Result.success(schoolRepository.findSchoolById(id));
    }

    @GetMapping("/search")
    public Result searchByName(String name){
        return schoolService.searchByName(name);
    }
}
